﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>驰骋工作流</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <link href="../CCForm/JS/mselector.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <script src="../Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <link href="../Comm/JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <script src="../Comm/JS/Calendar/WdatePicker.js" type="text/javascript"></script>

    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <link href="../Scripts/bootstrap/css/font-awesome.css" rel="Stylesheet" />
    <script type="text/javascript" src="../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.cokie.min.js"></script>
    <script src="../Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>
    <script src="../CCForm/JS/mtags.js" type="text/javascript"></script>
    <style type="text/css">
        *{
            margin:0px;
            padding:0px;
        }
        .ccflow-input-span-container {
            border: 0;
        }

        th {
            border-width: 1px;
            border-color: #C2D5E3;
            border-style: solid;
            line-height: 25px;
            color: #0a0a0a;
            white-space: nowrap;
            padding: 5px 2px;
            background-color: #e0ecff;
            font-size: 14px;
            text-align: left;
            font-size: 12px;
            font-weight: bolder;
        }
    </style>
    <script type="text/javascript" language="javascript">
        var currSelectNode = "";
        $(function () {

            var html = "<table class='table table-hover table-bordered' style='width:100%;' >";
            html += "<tr>";
            html += "<th width='5%'>步骤</th>";
            html += "<th width='*'>节点</th>";
            html += "<th width='50%'>处理人</th>";
            //html += "<th width='15%'>应完成时间</th>";
            html += "<th width='200px'>操作</th>";
            html += "</tr>";
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            var data = handler.DoMethodReturnJSON("TransferCustom_Init");

            var nds = data["WF_Node"]; //节点.
            var tcs = data["WF_TransferCustoms"]; //选择的接受人.
            var gwls = data["WF_GenerWorkerList"]; //选择的接受人.

            //输出已经走过的节点.
            html += "<tr><th colspan=5>已经运行的节点</tr>";
            for (var i = 0; i < gwls.length; i++) {
                var gwl = gwls[i];

                html += "<tr>";
                html += "<td >" + gwl.FK_Node + " </td>";
                html += "<td >" + gwl.FK_NodeText + " </td>";
                html += "<td >" + gwl.FK_EmpText + " </td>";
                html += "<td >无</td>";
                html += "</tr>";
            }


            //要排列的节点.
            var IsShowSave = false;
            html += "<tr><th colspan=5>运行的节点</tr>";
            for (var i = 0; i < tcs.length; i++) {
                var tc = tcs[i];
                if (tc.IsEnable == 0)
                    continue;
                html += "<tr>";
                html += "<td>" + tc.FK_Node + " </td>";
                html += "<td>" + tc.NodeName + " </td>";
                html += "<td >";
                //处理接收人的事件
                html += "<div id='" + tc.FK_Node + "_mtags' style='width:99%'  class='mtags'></div>";
                html += " </td>";
                //if (tc.PlanDT != null && tc.PlanDT != "") {
                //    IsShowSave = true;
                //    html += "<td><input type='text' id='"+tc.MyPK+"' name='CHTime' value='" + tc.PlanDT + "' onfocus='WdatePicker({dateFmt:\"yyyy-MM-dd HH:mm\"})'  class='form-control Wdate' style='width:150px;display:inline'/></td>";
                //} else {
                //    html += "<td></td>";
                //}
                html += "<td style='text-align:center; line-height:50%;  padding:3px;'><a class='btn btn-default'; href=\"javascript:DoUp('" + tc.MyPK + "');\">上移</a>&nbsp&nbsp&nbsp&nbsp<a class='btn btn-default'; href=\"javascript:DoDown('" + tc.MyPK + "');\">下移</a>&nbsp&nbsp&nbsp&nbsp<a class='btn btn-default'; href=\"javascript:Remove('" + tc.MyPK + "');\">排除</a></td>";
                html += "</tr>";
            }

            //可选步骤.
            html += "<tr><th colspan=5>可选步骤</tr>";
            for (var i = 0; i < tcs.length; i++) {
                var tc = tcs[i];
                if (tc.IsEnable == 1)
                    continue;

                html += "<tr>";
                html += "<td>" + tc.FK_Node + " </td>";
                html += "<td>" + tc.NodeName + " </td>";
                html += "<td>" + tc.WorkerName + " </td>";

                html += "<td>[<a class='btn btn-default' href=\"javascript:Add('" + tc.MyPK + "');\">增加</a>]</td>";
                html += "</tr>";
            }

            $("#docs").html(html);
            var initJsonData = [];
            var dept = getQueryStringByNameFromUrl("?" + $.cookie('CCS'), "FK_Dept");
            if (dept == null || dept == '' || dept == undefined) {
                dept = $.cookie('FK_Dept');
            }

            if (dept == null || dept == '' || dept == undefined) {
                var u = new WebUser();
                dept = u.FK_Dept;
            }

            if (dept == undefined) {
                dept = "0";
            }

            for (var i = 0; i < tcs.length; i++) {
                initJsonData = [];
                var tc = tcs[i];
                var workers = tc.Worker.split(',');
                var workerNames = tc.WorkerName.split(',');
                var FK_Node = tc.FK_Node;
                $.each(workers, function (k, o) {
                    if (o != null && o != "")
                        initJsonData.push({
                            "No": o,
                            "Name": workerNames[k],
                            "MyPK": tc.MyPK
                        });
                });
                var mtags = $("#" + tc.FK_Node + "_mtags");
                mtags.mtags({
                    "fit": true,
                    "onUnselect": function (record) {
                        RemoveEmp(record.MyPK, record.No, record.Name);
                    }
                });

                if (initJsonData.length != 0)
                    mtags.mtags("loadData", initJsonData);
            }

            $.each($(".mtags"), function (i, mtags) {
                var w = window.parent.document.body.clientWidth - 300;
                var h = window.parent.document.body.clientHeight - 40;
                $(mtags).bind("click", function () {
                    currSelectNode = $(mtags).attr("id").replace("_mtags", "");
                    var url = "./SelectEmps.htm?FK_Dept=" + dept + "&FK_Node=" + currSelectNode + "&s=" + Math.random();
                    $('#iframeSelectEmpsForm').attr('src', url);
                    $('#SelectEmpsModal').modal().show();
                });

            });

            if (IsShowSave == true)
                $("#IsShowSave").show();

        })

        //设置选中的人员
        function selectEmpsWindowClose(data) {

            $('#SelectEmpsModal').modal('hide');
            if (data == '取消') {
                return;
            }
            var val = frames["iframeSelectEmpsForm"].window.returnVal;
            var mypk = currSelectNode + "_" + GetQueryString("WorkID");
            var en = new Entity("BP.WF.TransferCustom", mypk);
            en.Worker = en.Worker + "," + val.No + ",";
            en.WorkerName = en.WorkerName + "," + val.Name + ",";
            en.Update();
            InitMtags($("#" + en.FK_Node + "_mtags"), en.MyPK, en.Worker, en.WorkerName);

        }

        //初始化接收人员列表
        function InitMtags(mtags, MyPK, worker, workerName) {
            var workers = worker.split(',');
            var workerNames = workerName.split(',');
            var initJsonData = [];
            $.each(workers, function (k, o) {
                if (o != null && o != "")
                    initJsonData.push({
                        "No": o,
                        "Name": workerNames[k],
                        "MyPK": MyPK
                    });
            });
            mtags.mtags("loadData", initJsonData);
        }

        //删除人员
        function RemoveEmp(mypk, empNo, empName) {
            var en = new Entity("BP.WF.TransferCustom", mypk);
            en.Worker = en.Worker.replace(empNo + ",", "");
            en.WorkerName = en.WorkerName.replace(empName + ",", "");
            en.Update();
            InitMtags($("#" + en.FK_Node + "_mtags"), mypk, en.Worker, en.WorkerName);
        }
        function DoUp(myPK) {

            var en = new Entity("BP.WF.TransferCustom", myPK);
            en.DoMethodReturnString("DoUp");
            window.location.href = window.location.href;
        }

        function DoDown(myPK) {

            var en = new Entity("BP.WF.TransferCustom", myPK);
            en.DoMethodReturnString("DoDown");
            window.location.href = window.location.href;
        }


        function Add(myPK) {

            var en = new Entity("BP.WF.TransferCustom", myPK);
            en.IsEnable = 1;
            en.Update();
            window.location.href = window.location.href;
        }
        function Remove(myPK) {
            var ens = new Entities("BP.WF.TransferCustoms");
            ens.Retrieve("WorkID", GetQueryString("WorkID"), "IsEnable", 1);
            if (ens.length == 1) {
                alert("流转自定义必须选择一个游离态节点，当前只有一个游离态节点不能移除");
                return;
            }
            var en = new Entity("BP.WF.TransferCustom", myPK);
            en.IsEnable = 0;
            en.Update();
            window.location.href = window.location.href;
        }
        function Save() {
            //获取需要保存时间的数据
            var tfs = $('input[name=CHTime]');
            if (tfs.length == 0)
                return;
            var workId = GetQueryString("WorkID");
            $.each(tfs, function (i, obj) {
                var id = obj.id;
                if (obj.value == "") {
                    alert("节点" + id.replace("_" + workId, "") + "不能为空");
                    return;
                }
                var en = new Entity("BP.WF.TransferCustom");
                en.SetPKVal(id);
                en.RetrieveFromDBSources();
                en.MyPK = id;
                en.PlanDT = obj.value;
                en.Save();

            });

        }
    </script>
</head>
<body>
    <form id="cc">
        <center>
            <h3>流转设置</h3>
            <table style="width: 90%;">

                <tr style="margin-top:20px;">
                    <td>
                        <div id="docs" name="docs" style="width: 100%">
                        </div>
                    </td>
                </tr>

            </table>
        </center>
    </form>
    <div class="modal fade" id="SelectEmpsModal">
        <div class="modal-dialog">
            <div class="modal-content" style="border-radius: 0px; width:100%;">
                <div class="modal-header">
                    <button type="button" class="close" style="color: #000; opacity: 1;" data-dismiss="modal"
                        aria-hidden="true">
                        &times;</button>
                    <h4 class="modal-title">
                        接受人</h4>
                </div>
                <div class="modal-body">
                    <iframe style="width: 100%; border: 0px; height: 400px;" id="iframeSelectEmpsForm"
                        name="iframeSelectEmpsForm"></iframe>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
</body>
</html>
